<?php


  function ends_with($haystack = '', $needle = '')
  {
  	return strrev($needle) == substr(strrev($haystack), 0, strlen($needle));
  }
  
	
  
  function error($str = '')
  {
  	$_SESSION['messages']['errors'][] = $str;
  	return false;
  }
  
  
  
  function errors($errors = false)
  {
  	foreach ($errors as $error) error($error);
  }
  
  
  
  function ext_to_mime($filename = false)
  {
  	$ext = (strstr($filename, '.')) ? substr($filename, strrpos($filename, '.')) : $filename;
  	$ext = trim($ext, '.');
  	
  	switch ($ext) {
  		case 'jpeg':
  		case 'jpg':
  			return 'image/jpeg';
  		break;
  		
  		case 'png':
  			return 'image/png';
  		break;
  			
  		case 'gif':
  			return 'image/gif';
  		break;
  		
  		default:
  			return 'text/plain';
  		break;
  	} 
  }